<script>
	import store from '@/store'
	import storage from '@/utils/storage'
	import commonFun from './core/common'
	import * as setting from '@/api/setting'
	import * as util from './utils/util'
	import {
		getSceneData
	} from './core/app'


	import {
		mapState,
		mapMutations
	} from 'vuex';
	import * as SettingApi from '@/api/setting'
	export default {
		onLaunch({
			path,
			query,
			scene
		}) {
			commonFun();
			this.getBaseInit();
			this.baseInit()
			console.log(2222222222);
			console.log(query);
			this.onStartupQuery(util.default.isObject(query) ? query : {})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},

		methods: {
			...mapMutations(['SET_TOKEN', 'SET_USER_ID']),
			baseInit() {
				let token = uni.getStorageSync('token')
				let userId = uni.getStorageSync('userId')
				if (userId) {
					this.SET_USER_ID(userId)
				}
				if (token) {
					this.SET_TOKEN(token)
				}
			},
			getBaseInit() {
				SettingApi.getBaseInit({
					'version': '1.0.0'
				}).then((res) => {
					storage.set('baseInfo', res.data)
				}).catch((e) => {
					return this.$toast('接口请求错误');
				})
			},
			// app启动参数
			onStartupQuery(query) {
				// 获取二维码场景值
				console.log(query);
				const scene = getSceneData(query)
				// 记录推荐人ID
				const refereeId = query.refereeId ? query.refereeId : scene.uid
				console.log('11111111', refereeId);
				refereeId > 0 && (this.setRefereeId(refereeId))
			},

			// 记录推荐人ID
			setRefereeId(refereeId) {
				uni.setStorageSync('refereeId', refereeId)
			},


		}

	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	@import "common/css/base.css";
</style>